package progress.exa4;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;

public class RandomAccessFileStudy {

    public static void main(String[] args) throws IOException {
        randomAccessFileStudy();
    }

    /**
     * 随机流学习
     */
    public static void randomAccessFileStudy() throws IOException {
        RandomAccessFile randomAccessFile = null;
        try{
            randomAccessFile = new RandomAccessFile("麻子.txt","rw");
            // 使用随机流进行读操作
            while (true) {
                String s = randomAccessFile.readLine();
                if(s==null) break;
                System.out.println(s);
            }
            randomAccessFile.write("\n你好,我是测试".getBytes(StandardCharsets.UTF_8));
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(randomAccessFile!=null) {
                randomAccessFile.close();
            }
        }
    }

}

